package com.zl.tby.controller;

import com.zl.tby.core.common.R;
import com.zl.tby.model.TbyFireRating;
import com.zl.tby.service.ITbyFireRatingService;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.core.handle.MethodType;
import org.noear.solon.validation.annotation.Valid;
import org.noear.solon.validation.annotation.Validated;

/**
 * 火险等级配置
 * @author changpeng
 * @version 1.0
 * @since 2024/8/6 20:22
 */
@Valid
@Controller
@Mapping("/fire_rating")
public class TbyFireRatingController {

    @Inject
    private ITbyFireRatingService tbyFireRatingService;

    /**
     * 保存或新增
     * @param form: 表单对象
     * @return 操作结果
     */
    @Mapping(value = "/save", method = MethodType.POST)
    public R<TbyFireRating> saveOrUpdate(@Validated TbyFireRating form) {
        try {
            if (form.getId() == null) {
                return tbyFireRatingService.add(form);
            }
            return tbyFireRatingService.update(form);
        } catch (Exception ex) {
            ex.printStackTrace();
            return R.failed(ex.getMessage());
        }
    }

    /**
     * 获取详情
     * @return 结果
     */
    @Mapping(value = "/get", method = MethodType.GET)
    public R<TbyFireRating> get() {
        TbyFireRating entity = this.tbyFireRatingService.get();
        return R.ok(entity);
    }

}
